package com.hxl.demo.controller;

import com.hxl.demo.entity.LaborContract;
import com.hxl.demo.service.LaborContractService;
import com.hxl.demo.tools.PageInfo;
import com.hxl.demo.tools.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
public class LaborContractController {
    @Resource
    private LaborContractService laborContractService;

    @RequestMapping(value = "/getAllLaborContract", method = RequestMethod.POST)
    public Result selectAll(@RequestParam(name ="begin") String begin, @RequestParam(name="length") String length, @RequestParam(name="username",required = false) String username){
        int start = begin == null ? 0 : Integer.parseInt(begin);
        int limit = length == null ? 15 : Integer.parseInt(length);
        if (start > 0) {
            start = (start - 1) * limit;
        } else {
            start = 0;
        }
        PageInfo<LaborContract> pageInfo = laborContractService.selectLaborContract(start, limit, username);
        if(pageInfo != null) {
            return Result.ok().data("page", pageInfo);
        } else {
            return Result.fail();
        }
    }
}
